package com.yunda.AJDeviceService.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import com.yunda.AJDeviceService.common.service.RedisService;
import com.yunda.AJDeviceService.dao.QueryDataDao;
import com.yunda.AJDeviceService.data.entity.GetRunTimeParam;
import com.yunda.AJDeviceService.data.entity.QueryCountParam;
import com.yunda.AJDeviceService.data.vo.QueryCountVo;
import com.yunda.AJDeviceService.service.DeviceRunTimeService;
import com.yunda.AJDeviceService.service.QueryDataService;

/**
 * AJDeviceService
 * @description 总部查询
 * @author ljc
 * @create 2023年2月14日 下午1:27:20
 */
@Service
public class QueryDataServiceImpl extends ServiceImpl<QueryDataDao, QueryCountParam> implements QueryDataService{

	@Autowired
	private RedisService redisService;
	@Autowired
	private DeviceRunTimeService deviceRunTimeService;
	@Autowired
	private QueryDataDao queryDataDao;
	
	@Override
	public List<QueryCountVo> queryCountData(QueryCountParam param) {
		List<QueryCountVo> list=queryDataDao.queryCountData(param);
		for(QueryCountVo vo:list) {
			vo.setDeviceStatus(!ObjectUtils.isEmpty(redisService.get(vo.getDeviceCode()))?"是":"否");
			
			GetRunTimeParam timeParam=new GetRunTimeParam();
			timeParam.setFb_code(param.getFb_code());
			timeParam.setDevice_supplier(vo.getDeviceSupplier());
			timeParam.setDevice_code(vo.getDeviceCode());
			timeParam.setStart_time(param.getStart_time());
			timeParam.setEnd_time(param.getEnd_time());
			double runHour= deviceRunTimeService.getRunTime(timeParam);
			
			vo.setRunTime(runHour);
		}
		return list;
	}
}
